package org.ykh.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.ykh.springcloud.entities.CommonResult;
import org.ykh.springcloud.entities.Payment;

/**
 * @author ykh
 * @create 2022-01-03 22:17
 */
@RestController
@Slf4j
public class OrderController {

//    public static final String PaymentSrv_URL = "http://localhost:8001";
    public static final String PaymentSrv_URL = "http://CLOUD-PAYMENT-SERVICE";//使用服务集群的名称spring:application:name: cloud-payment-service
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/consumer/payment/create")
    public CommonResult create(Payment payment){
        log.info("开始处理请求");
        return restTemplate.postForObject(PaymentSrv_URL + "/payment/create", payment, CommonResult.class);
    }

    @GetMapping("/consumer/payment/getPaymentById/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id")Long id){
        log.info("开始处理请求");
        return restTemplate.getForObject(PaymentSrv_URL + "/payment/getPaymentById/" + id, CommonResult.class, id);
    }
}
